package com.hzspace.mybatis.mapper;

import com.hzspace.mybatis.enums.UserSexEnum;
import com.hzspace.mybatis.model.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapper {
	
	@Select("SELECT * FROM users")
	@Results({
		@Result(property = "userSex",  column = "userSex", javaType = UserSexEnum.class),
		@Result(property = "nickName", column = "nickName")
	})
	List<User> getAll();
	
	@Select("SELECT * FROM users WHERE id = #{id}")
	@Results({
		@Result(property = "userSex",  column = "userSex", javaType = UserSexEnum.class),
		@Result(property = "nickName", column = "nickName")
	})
	User getOne(Long id);

	@Insert("INSERT INTO users(userName,passWord,userSex) VALUES(#{userName}, #{passWord}, #{userSex})")
	void insert(User user);

	@Update("UPDATE users SET userName=#{userName},nickName=#{nickName} WHERE id =#{id}")
	void update(User user);

	@Delete("DELETE FROM users WHERE id =#{id}")
	void delete(Long id);

}